using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UIPack;
using FairyGUI;
using DG.Tweening;
using Newtonsoft.Json;

public enum ConditionType {
    someNodeExpanded  = 1,//某节点已经展开（状态）
}

public enum PswdType {
    numPswd = 1,//数字密码
    imgPswd = 2,//图片密码
    strPswd = 3,//字符串密码

    empty = 50,//没有

    special = 100,//特殊



}
public enum NodeEventType {
    win = 1,//游戏胜利
    destoryNode = 2,//摧毁一个节点
    changeNodeNoEffect = 3,//改变指定节点,但没有动画
    changeNode = 4,//改变指定节点,
    enterLevel = 5,//进入新level（读取新的json配置）

    expandNode= 6,//展开节点
    shakeNode = 7,
    say = 8,
    sayAvatar = 9,

    // shakeAndSay = 6,//抖动和 发出语音


    playNodeAnim = 100,//播放节点的动画效果，(发光，发声音,火焰) 等等

    
    //        ["5","1", "你回想起刚才看到的咒语...","您的颈椎被折断了，倒在了灵堂，你死了！", "圆头圆脑圆肚皮！", "嗡阿吽班杂咕噜叭嘛悉地吽", "*&%&#￥@#￥&%#￥.."],
    // [倒计时，正确答案索引，提问描述，答案0，答案1，答案2......]  特别注意 如果正确答案索引是-1那么表示 等CD耗尽才是对的
    question = 150,//提问

    wait = 180,//等待一段时间

    playDie = 200, //主角死亡，游戏结束
    
    levelClear = 250, //通关，此关结束

    getItem = 300,//获得道具

    editor = 1234, //

}




public class LvHelper
{
    public static int IdIdx = 0;
    public static int GetIdIdx()
    {
        IdIdx++;
        if (IdIdx >= 1000000000) {
            IdIdx = 0;
        }
        return IdIdx;
    }

     public static string GetEventTypeName(NodeEventType eventType) {
        switch (eventType) {
            case NodeEventType.win:
                return "游戏胜利";
            case NodeEventType.destoryNode:
                return "摧毁一个节点";
            case NodeEventType.changeNodeNoEffect:
                return "改变指定节点,但没有动画";
            case NodeEventType.changeNode:
                return "改变指定节点";
            case NodeEventType.enterLevel:
                return "进入新level";
            case NodeEventType.expandNode:
                return "展开节点";
            case NodeEventType.shakeNode:
                return "节点抖动";
            case NodeEventType.say:
                return "说话";
            case NodeEventType.sayAvatar:
                return "角色说话";
            case NodeEventType.playNodeAnim:
                return "播放节点动画";
            case NodeEventType.question:
                return "提问";
            case NodeEventType.wait:
                return "等待";
            case NodeEventType.playDie:
                return "主角死亡，游戏结束";
            case NodeEventType.levelClear:
                return "通关，此关结束";
            case NodeEventType.getItem:
                return "获得道具";
            case NodeEventType.editor:
                return "编辑器";
            default:
                return "未知事件";
        }
    }

    public static float LineDistance = 1.8f;

    public static LvEntity CurrLvCfg;
    public static ComNode CurrSelectNode = null;
    public static ComNode CurrDragNode = null;
    /// <summary>
    /// 当前解密的谜题
    /// </summary>
    public static ComNode CurrCrackingPswdNode = null;
    //public static GameNodeEntity GetPairById(string id) {
    //    var pairArr = CurrLvCfg.pairArr;
    //    for (int i = 0; i < pairArr.Length; i++) {
    //        if (pairArr[i].id == id) {
    //            return pairArr[i];
    //        }
    //    }

    //    return null;
    //}
    
    public static GameNodeEntity GetChangeNodeById(string id) {
        var changeNodeArr = CurrLvCfg.changeNodeList;
        for (int i = 0; i < changeNodeArr.Count; i++) {
            if (changeNodeArr[i].id == id) {
                return changeNodeArr[i];
            }
        }

        return null;
    }


   



    public static void RemoveComNodeFromDic(string nodeId) {
        Id2GameNode.Remove(nodeId);
        Id2GameNodeEntity.Remove(nodeId);
    }



    public static Dictionary<string, ComNode> Id2GameNode = new Dictionary<string, ComNode>();
    public static IDictionary<string, GameNodeEntity> Id2GameNodeEntity = new Dictionary<string, GameNodeEntity>();
    
    public static GameObject GameNodePrefabStatic;
    public static GameObject LinePrefabStatic;
    
    public static GameObject NodeCon;
    public static GameObject LineCon;
    //public static ComNode CreateGameNode(GameNodeEntity entity, Vector3 parentPos, Vector3 rotationVec3, GameObject parentGameObject = null, bool hasAnim = true) {
    //    if (entity.randomArr != null)
    //    {
    //        var nodeId = entity.randomArr[UnityEngine.Random.Range(0, entity.randomArr.Length)];
    //        entity = GetChangeNodeById(nodeId);
    //    }
        
    //    Vector3 position;
    //    if (entity.LineDistance == 0f) {
    //        position = parentPos + rotationVec3 * LvHelper.LineDistance;
    //    }
    //    else {
    //        position = parentPos + rotationVec3 * entity.LineDistance;
    //    }

    //    var n = GameObject.Instantiate(GameNodePrefabStatic);
    //    n.transform.parent = NodeCon.transform;
    //    Id2GameNodeEntity[entity.id] = entity;

    //    //if (parentGameObject != null) {
    //    //    var parentComNode =  n.GetComponent<UIPanel>().ui as ComNode;
    //    //    var list = parentComNode.GetSubNodes();
    //    //}
         
    //    var p0 = n.GetComponent<UIPanel>();
    //    //设置renderCamera的方式
    //    //设置renderMode的方式
    //    p0.container.renderMode = RenderMode.ScreenSpaceCamera;
    //    p0.container.renderCamera = GameHelper.NodeCamera;

    //    var comNode0 =  p0.ui as UIPack.ComNode;
    //    comNode0.Init(entity);
    //    comNode0.GameObject = n;
    //    comNode0.ParentGameObject = parentGameObject;
    //    comNode0.UIPanelRef = p0;
  
    //    if (parentGameObject != null) {
    //        var line = GameObject.Instantiate(LinePrefabStatic);
    //        line.transform.parent = LineCon.transform;
    //        var drawLine = line.GetComponent<DrawLine>();
    //        drawLine.G0 = parentGameObject;
    //        drawLine.G1 = n;


    //        if (hasAnim) {
    //            n.transform.position = parentGameObject.transform.position;
    //            n.transform.DOMove(position, 0.2f).OnComplete(()=>{
    //                comNode0.CanTouch = true;
    //            });
    //        }
    //        else
    //        {
    //            n.transform.position = position;
    //        }

    //        comNode0.Line = line;
    //    }
    //    else
    //    {
    //        n.transform.position = parentPos;
    //    }

    //    Id2GameNode[entity.id] = comNode0;

    //    return comNode0;
    //}
    
}
